
#include <cpp/memory.hpp>

#include "catch.hpp"


TEST_CASE("tagged_ptr")
{
	using namespace cpp::utility;

	tagged_ptr<int> p{ new int(0),2 };
	REQUIRE(p.tag() == 2);


	tagged_ptr<int> p2{ new int(1),1 };

	REQUIRE(p2.tag() == 1);

	p.swap(p2);

	REQUIRE(*p == 1);
	REQUIRE(*p2 == 0);

	REQUIRE(p.tag() == 2);
	REQUIRE(p2.tag() == 1);

	p2.tag(2);
	REQUIRE(p2.tag() == 2);

	p.swap(p2);

	REQUIRE(*p == 0);
	REQUIRE(*p2 == 1);


}


